package com.example.sys.module.mode;

import com.example.utils.StringUtils;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class SysModuleInfo {
    private String shortName;
    private String simpleName;
    private String entityName;
    private String comment;
    private Class<?> entityClass;
    private Class<?> formClass;
    private String baseRole;
    private List<SysColumnInfo> columnInfos = new ArrayList<>();

    public String getShortName() {
        if (StringUtils.isEmpty(this.shortName)) {
            String simpleName = this.entityClass.getSimpleName();
            this.shortName = StringUtils.toLowerCaseFirstOne(simpleName);
        }
        return shortName;
    }

    public String getSimpleName() {
        if (StringUtils.isEmpty(this.simpleName)) {
            this.simpleName = this.entityClass.getSimpleName();
        }
        return simpleName;
    }

    public String getEntityName() {
        if (StringUtils.isEmpty(this.entityName)) {
            this.entityName = this.entityClass.getName();
        }
        return entityName;
    }

    public String getBaseRole() {
        if (StringUtils.isEmpty(this.baseRole)) {
            String simpleName = this.getSimpleName();
            this.baseRole = StringUtils.camel2under(simpleName).toUpperCase();
        }
        return baseRole;
    }

    public SysColumnInfo getSysColumnInfo(String property) {
        for (SysColumnInfo columnInfo : this.getColumnInfos()) {
            if (columnInfo.getProperty().equals(property)) {
                return columnInfo;
            }
        }
        return null;
    }
}
